package acwing;

import java.io.*;

public class ac1209_2 {
    static final int N = 20;
    static int n, ans;
    static int[] path = new int[N];
    static boolean[] st = new boolean[N];
    static StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

    static int nextInt() throws IOException {
        cin.nextToken();
        return (int) cin.nval;
    }

    static int calc(int l, int r) {
        int res = 0;
        for (int i = l; i <= r; i ++ ) {
            res = res * 10 + path[i];
        }
        return res;
    }

    static void dfs(int u) {
        if (u == 9) {
            for (int i = 0; i < 7; i ++ ) {
                for (int j = i + 1; j < 8; j ++ ) {
                    int a = calc(0, i);
                    int b = calc(i + 1, j);
                    int c = calc(j + 1, 8);
                    if (a * c + b == c * n) ans ++ ;
                }
            }
        }

        for (int i = 1; i <= 9; i ++ ) {
            if (!st[i]) {
                st[i] = true;
                path[u] = i;
                dfs(u + 1);
                st[i] = false;
            }
        }
    }

    public static void main(String[] args) throws IOException{
        n = nextInt();
        dfs(0);
        out.println(ans);
        out.close();
    }
}